

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Core;
using JTC.MiniCommerce.Localization;

namespace JTC.MiniCommerce.Web.admin.controls.sitesettings {
  public partial class analytics : SiteSettingsControl {

    #region Page Events

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {
      try {
        if (pnlSettings.Visible) {
          SetAnalyticsProperties();
          if (!Page.IsPostBack) {
            txtAnalytics.Text = HttpUtility.HtmlDecode(SiteSettings.Analytics);
          }
        }
      }
      catch (Exception ex) {
        Logger.Error(typeof(analytics).Name + ".Page_Load", ex);
        base.MasterPage.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
      }
    }

    /// <summary>
    /// Handles the Click event of the btnSave control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void btnSave_Click(object sender, EventArgs e) {
      try {
        SiteSettings.Analytics = HttpUtility.HtmlEncode(txtAnalytics.Text.Trim());
        base.Save(SiteSettings);
      }
      catch (Exception ex) {
        Logger.Error(typeof(analytics).Name + ".btnSave_Click", ex);
        base.MasterPage.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
      }
    }

    #endregion

    #region Methods

    #region Private

    /// <summary>
    /// Sets the analytics properties.
    /// </summary>
    private void SetAnalyticsProperties() {
      this.Page.Title = LocalizationUtility.GetText("titleSiteSettingsAnalytics");
      pnlSettings.GroupingText = LocalizationUtility.GetText("pnlAnalytics");
      LocalizationUtility.AddLabelText(lblAnalytics);
      LocalizationUtility.AddButtonText(btnSave);
      LocalizationUtility.AddHoverHelp(hlAnalyticsHelp);
    }

    #endregion

    #endregion

  }
}